package com.binance.mbxgateway.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.binance.master.models.APIRequest;
import com.binance.master.models.APIResponse;
import com.binance.mbxgateway.api.IPriceApi;
import com.binance.mbxgateway.vo.request.price.GetMbxPriceRequest;
import com.binance.mbxgateway.vo.request.price.GetPriceRequest;
import com.binance.mbxgateway.web.service.IPriceService;

@RestController
public class PriceController implements IPriceApi {

    @Autowired
    private IPriceService priceService;

    @Override
    public APIResponse<Double> getPrice(@RequestBody @Validated APIRequest<GetMbxPriceRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.priceService.getMbxPrice(request.getBody().getSymbol()));
    }

    @Override
    public APIResponse<String> get24hrTicker(@RequestBody @Validated APIRequest<GetPriceRequest> request)
            throws Exception {
        return APIResponse.getOKJsonResult(this.priceService.get24hrTicker(request.getBody().getSymbol()));
    }

}
